Make tools/check scripts cross-friendly
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 22 Jan 2008 09:44:17 +0000 (09:44 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 22 Jan 2008 09:44:17 +0000 (09:44 +0000)
This patch introduces tools/check/funcs.sh with some
cross-friendly abstractions, then modifies the check_*
scripts to use them.

Signed-off-by: Aron Griffis <aron@hp.com>
16 files changed:
tools/check/check_brctl
tools/check/check_crypto_lib
tools/check/check_curl
tools/check/check_iproute
tools/check/check_openssl_devel
tools/check/check_python
tools/check/check_python_devel
tools/check/check_python_xml
tools/check/check_udev
tools/check/check_x11_devel
tools/check/check_xgettext
tools/check/check_xml2
tools/check/check_zlib_devel
tools/check/check_zlib_lib
tools/check/chk
tools/check/funcs.sh [new file with mode: 0644]

index e92612023571b991dd9cb177b449c13947f9afda..782af5a06f176a22264f29c6db46bf1d25feb502 100755 (executable)
@@ -1,27 +1,13 @@
 #!/bin/sh
 # CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
-case ${OS} in
+case $OS in
 OpenBSD|NetBSD|FreeBSD)
-       # These systems have a bridge builtin
-       TOOL="brconfig"
-       which ${TOOL} 1>/dev/null 2>&1 || RC=1 
-       ;;
+       has_or_fail brconfig ;;
 Linux)
-       TOOL="brctl"
-       which ${TOOL} 1>/dev/null 2>&1 || RC=1
-       ;;
+       has_or_fail brctl ;;
 *)
-       TOOL=""
-       echo "Unknown OS" && RC=1
-       ;;
+       fail "unknown OS" ;;
 esac
-
-if test ${RC} -ne 0; then
-       echo
-       echo " *** Check for the bridge control utils (${TOOL}) FAILED"
-fi
-
-exit ${RC} 
index 4717cca7f9815ecd3f626d1f1d9960dc07de5b46..1292d791d1b91441ccfd20d49b024c9a2dfde94e 100755 (executable)
@@ -1,23 +1,11 @@
 #!/bin/sh
 # CHECK-BUILD CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
-case $(uname -s) in
+case $OS in
 FreeBSD|NetBSD|OpenBSD)
-       exit 0
-       ;;
-*)
-       ;;
+       exit 0 ;;
 esac
 
-PATH=/sbin:$PATH
-set -e
-ldconfig -p 2>&1 | grep -q libcrypto.so || RC=1
-
-if test ${RC} -ne 0; then
-        echo
-        echo " *** Check for crypto library FAILED"
-fi
-
-exit ${RC}
+has_lib libcrypto.so || fail "missing libcrypto.so"
index 7176c896c74920f63caf4d4e3ab4388c60c3b904..eb6add3ef4e1fc8cafc7600c85d605f02a1926d8 100755 (executable)
@@ -1,38 +1,13 @@
 #!/bin/sh
 # CHECK-BUILD CHECK-INSTALL
 
-if [ ! "$LIBXENAPI_BINDINGS" = "y" ]
-then
-    echo -n "unused, "
-    exit 0
-fi
-
-RC=0
-
-CURL_CONFIG="$(which curl-config)"
-tmpfile=$(mktemp)
-
-if test -z ${CURL_CONFIG}; then
-    RC=1
-else
-    ${CURL_CONFIG} --libs 2>&1 > /dev/null
-    RC=$?
-fi
+. funcs.sh
 
-if test $RC -ne 0; then
-    echo "FAILED"
-       echo " *** curl-config is missing. "
-    echo " *** Please install curl-devel."
-elif ! ld $($CURL_CONFIG --libs) -o $tmpfile >/dev/null 2>&1; then
-    echo "FAILED"
-    echo " *** dependency libraries for curl are missing: "
-    RC=1
-    for i in $(ld $($CURL_CONFIG --libs) -o $tmpfile 2>&1 >/dev/null); do
-        case $i in
-        -l*) echo lib${i#-l}
-        esac
-    done
+if [ "$LIBXENAPI_BINDINGS" != "y" ]; then
+       echo -n "unused, "
+       exit 0
 fi
-rm -f $tmpfile
 
-exit $RC
+has_or_fail curl-config
+curl_libs=`curl-config --libs` || fail "curl-config --libs failed"
+test_link $curl_libs || fail "dependency libraries for curl are missing"
index 35af9a4c4b8c954478143860b1dff621437d3574..a900165436a899f5df0aad99519ea2a365d2eba5 100755 (executable)
@@ -1,26 +1,15 @@
 #!/bin/sh
 # CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
-case ${OS} in
+PATH=/sbin:$PATH
+
+case $OS in
 OpenBSD|NetBSD|FreeBSD)
-       TOOL="ifconfig"
-       eval ${TOOL} -a 1>/dev/null 2>&1 || RC=1 
-       ;;
+       has_or_fail ifconfig ;;
 Linux)
-       TOOL="ip addr"
-       eval ${TOOL} list 1>/dev/null 2>&1 || RC=1 
-       ;;
+       has_or_fail ip ;;
 *)
-       TOOL=""
-       echo "Unknown OS" && RC=1 
-       ;;
+       fail "unknown OS" ;;
 esac
-
-if test ${RC} -ne 0; then
-       echo
-       echo " *** Check for iproute (${TOOL}) FAILED"
-fi
-
-exit ${RC} 
index c05a29dd8f3345f87ad89c3b434027b7c56baf46..1b4d1581cddaa695421322d8cfcf9cbe29f5c15e 100755 (executable)
@@ -1,14 +1,6 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
-set -e
-test -r /usr/include/openssl/md5.h || RC=1 
-
-if test ${RC} -ne 0; then
-       echo
-       echo " *** Check for openssl headers FAILED"
-fi
-
-exit ${RC}
+has_header openssl/md5.h || fail "missing openssl headers"
index 6d665ea4b24f2a4b6a6f042d1deb20d2ba36eb7a..feeb6fc5b0955c3658b65cb5993150c9221a58f6 100755 (executable)
@@ -1,16 +1,9 @@
 #!/bin/sh
 # CHECK-BUILD CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
 python -c '
 import sys
 sys.exit(sys.version_info[0] < 2 or sys.version_info[1] < 2)
-' || RC=1
-
-if test ${RC} -ne 0; then
-       echo
-       echo " *** Check for Python version >= 2.2 FAILED"
-fi
-
-exit ${RC} 
+' || fail "need python version >= 2.2"
index d2f05368d26f260536b84faf45dcd60211a78ee7..7630bb0241e9391ad760f9905ce9ce7cad293149 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
 python -c '
 import os.path, sys
@@ -9,11 +9,4 @@ for p in sys.path:
        if os.path.exists(p + "/config/Makefile"):
                sys.exit(0)
 sys.exit(1)
-' || RC=1 
-
-if test ${RC} -ne 0; then
-       echo
-       echo " *** Check for python development environment FAILED"
-fi
-
-exit ${RC}
+' || fail "can't find python devel files"
index faf56bb0837bb8923ec58d920bf7816f6669af7a..879c8a82d4675e9acaccccb0a6e167f96b734d5f 100755 (executable)
@@ -1,8 +1,7 @@
 #!/bin/sh
 # CHECK-INSTALL
 
-python -c 'import xml.dom.minidom' 2>/dev/null || {
-    echo
-    echo "  *** Check for python-xml package FAILED"
-    exit 1
-}
+. funcs.sh
+
+python -c 'import xml.dom.minidom' 2>/dev/null || \
+fail "can't import xml.dom.minidom"
index a4295cf4fafd303917d0ceb61be8ebc3eff8683d..169632bc355312606addc59c02b80015f0f78bbe 100755 (executable)
@@ -1,34 +1,19 @@
 #!/bin/sh
 # CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
-case ${OS} in
+case $OS in
 OpenBSD|NetBSD|FreeBSD)
-       TOOL="vnconfig"
-       which ${TOOL} 1>/dev/null 2>&1 || RC=1
+       has_or_fail vnconfig
        ;;
 Linux)
-       TOOL="udevinfo"
-       UDEV_VERSION="0"
-       test -x "$(which ${TOOL} 2>/dev/null)" && \
-               UDEV_VERSION=$(${TOOL} -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/')
-       if test "${UDEV_VERSION}" -ge 059; then
-               RC=0
-       else
-               TOOL="hotplug"
-               which ${TOOL} 1>/dev/null 2>&1 || RC=1
-       fi
+       has_or_fail udevinfo
+       [ "`udevinfo -V | awk '{print $NF}'`" -ge 59 ] 2>/dev/null || \
+               has hotplug || \
+               fail "udev is too old, upgrade to version 59 or later"
        ;;
 *)
-       TOOL=""
-       echo "Unknown OS" && RC=1
+       fail "unknown OS"
        ;;
 esac
-
-if test ${RC} -ne 0; then
-       echo
-       echo " *** Check for ${TOOL} FAILED"
-fi
-
-exit ${RC}
index 722df86344d8d622abe3653125c7a9f6f1b852f1..6956ce034b1f3198f18a2dfedf6b41d809bc1601 100755 (executable)
@@ -1,15 +1,8 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
-set -e
-test -r /usr/include/X11/keysymdef.h || \
-test -r /usr/X11R6/include/X11/keysymdef.h || RC=1
-
-if test ${RC} -ne 0; then
-       echo
-       echo " *** Check for x11 headers FAILED"
-fi
-
-exit ${RC}
+has_header X11/keysymdef.h || \
+has_header /usr/X11R6/include/X11/keysymdef.h || \
+fail "can't find X11 headers"
index 0781ec50d91e9bab7eefede67bf456bb2c895f7c..ac66e6864c10a57b2e03bc92a94c49580ca62cb6 100755 (executable)
@@ -1,14 +1,6 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
-TOOL="xgettext"
-which ${TOOL} 1>/dev/null 2>&1 || RC=1 
-
-if test ${RC} -ne 0; then
-       echo
-       echo " *** Check for the gettext utility (${TOOL}) FAILED"
-fi
-
-exit ${RC} 
+has_or_fail xgettext
index e8def042ad7be200b24d9b61221f5efb4ff63d90..8b1adbfdc090d7a3db9d734c6b76cde9c5ac9369 100755 (executable)
@@ -1,38 +1,14 @@
 #!/bin/sh
 # CHECK-BUILD CHECK-INSTALL
 
+. funcs.sh
+
 if [ ! "$LIBXENAPI_BINDINGS" = "y" -a ! "$ACM_SECURITY" = "y" ]
 then
     echo -n "unused, "
     exit 0
 fi
 
-RC=0
-
-XML2_CONFIG="$(which xml2-config)"
-tmpfile=$(mktemp)
-
-if test -z ${XML2_CONFIG}; then
-    RC=1
-else
-    ${XML2_CONFIG} --libs 2>&1 > /dev/null
-    RC=$?
-fi
-
-if test $RC -ne 0; then
-    echo "FAILED"
-       echo " *** xml2-config is missing. "
-    echo " *** Please install libxml2-devel."
-elif ! ld $($XML2_CONFIG --libs) -o $tmpfile >/dev/null 2>&1; then
-    echo "FAILED"
-    echo " *** dependency libraries for xml2 are missing: "
-    RC=1
-    for i in $(ld $($XML2_CONFIG --libs) -o $tmpfile 2>&1 >/dev/null); do
-        case $i in
-        -l*) echo lib${i#-l}
-        esac
-    done
-fi
-rm -f $tmpfile
-
-exit $RC
+has_or_fail xml2-config
+xml2_libs=`xml2-config --libs` || fail "xml2-config --libs failed"
+test_link $xml2_libs || fail "dependency libraries for xml2 are missing"
index 108e06a61625eac8198a395695aecb5db4a337ba..33236de872804219290b94bf55469419f6a4cb0c 100755 (executable)
@@ -1,14 +1,6 @@
 #!/bin/sh
 # CHECK-BUILD
 
-RC=0
+. funcs.sh
 
-set -e
-test -r /usr/include/zlib.h || RC=1
-
-if test ${RC} -ne 0; then
-       echo
-       echo " *** Check for zlib headers FAILED"
-fi 
-
-exit ${RC}
+has_header zlib.h || fail "can't find zlib headers"
index a4231d606afd7d171806139d2b210440e3ac5900..804b78374ebe969cb7c240bdfa925f60d5662fcc 100755 (executable)
@@ -1,24 +1,12 @@
 #!/bin/sh
 # CHECK-BUILD CHECK-INSTALL
 
-RC=0
+. funcs.sh
 
-case $(uname -s) in
+case $OS in
 FreeBSD|NetBSD|OpenBSD)
        exit 0
        ;;
-*)
-       ;;
 esac
 
-PATH=/sbin:$PATH
-
-set -e
-ldconfig -p 2>&1 | grep -q libz.so || RC=1
-
-if test ${RC} -ne 0; then
-       echo
-       echo " *** Check for zlib library FAILED"
-fi
-
-exit ${RC} 
+has_lib libz.so || fail "can't find zlib"
index d8eb2f17e344f54517b2bad13cbbbcf71ec9e2d3..e776cff3af8ca1b3f1bb2697f9b70e00e04f2cf7 100755 (executable)
@@ -7,17 +7,16 @@ func_usage ()
     echo
     echo "Check suitability for Xen build or install."
     echo "Exit with 0 if OK, 1 if not."
-    echo "Prints only failed tests."
     echo
     echo "Calling with 'clean' removes generated files."
     exit 1
 }
 
-PATH=${PATH}:/sbin:/usr/sbin
+PATH=$PATH:/sbin:/usr/sbin
 OS=`uname -s`
 export PATH OS
 
-if test "${OS}" = "SunOS"; then
+if [ "$OS" = "SunOS" ]; then
        exit 0
 fi
 
@@ -38,7 +37,7 @@ esac
 
 failed=0
 
-echo "Xen ${check} " $(date)
+echo "Xen ${check} " `date`
 for f in check_* ; do
     case $f in
         *~)
@@ -50,7 +49,7 @@ for f in check_* ; do
     if ! [ -x $f ] ; then
         continue
     fi
-    if ! grep -q ${check} $f ; then
+    if ! grep -Fq "$check" $f ; then
         continue
     fi
     echo -n "Checking $f: "
diff --git a/tools/check/funcs.sh b/tools/check/funcs.sh
new file mode 100644 (file)
index 0000000..d3fb60a
--- /dev/null
@@ -0,0 +1,85 @@
+# has is the same as which, except it handles cross environments
+has() {
+       if [ -z "$CROSS_COMPILE" ]; then
+               command which "$@"
+               return $?
+       fi
+
+       check_sys_root || return 1
+
+       # subshell to prevent pollution of caller's IFS
+       (
+       IFS=:
+       for p in $PATH; do
+               if [ -x "$CROSS_SYS_ROOT/$p/$1" ]; then
+                       echo "$CROSS_SYS_ROOT/$p/$1"
+                       return 0
+               fi
+       done
+       return 1
+       )
+}
+
+has_or_fail() {
+       has "$1" >/dev/null || fail "can't find $1"
+}
+
+has_header() {
+       case $1 in
+               /*) ;;
+               *) set -- "/usr/include/$1" ;;
+       esac
+
+       check_sys_root || return 1
+
+       test -r "$CROSS_SYS_ROOT$1"
+       return $?
+}
+
+has_lib() {
+       check_sys_root || return 1
+
+       # subshell to prevent pollution of caller's environment
+       (
+       PATH=/sbin:$PATH        # for ldconfig
+
+       # This relatively common in a sys-root; libs are installed but
+       # ldconfig hasn't run there, so ldconfig -p won't work.
+       if [ "$OS" = Linux -a ! -f "$CROSS_SYS_ROOT/etc/ld.so.cache" ]; then
+           echo "Please run ldconfig -r \"$CROSS_SYS_ROOT\" to generate ld.so.cache"
+           # fall through; ldconfig test below should fail
+       fi
+       ldconfig -p ${CROSS_SYS_ROOT+-r "$CROSS_SYS_ROOT"} | grep -Fq "$1"
+       return $?
+       )
+}
+
+test_link() {
+       # subshell to trap removal of tmpfile
+       (
+       unset tmpfile
+       trap 'rm -f "$tmpfile"; exit' 0 1 2 15
+       tmpfile=`mktemp` || return 1
+       ld "$@" -o "$tmpfile" >/dev/null 2>&1
+       return $?
+       )
+}
+
+# this function is used commonly above
+check_sys_root() {
+       [ -z "$CROSS_COMPILE" ] && return 0
+       if [ -z "$CROSS_SYS_ROOT" ]; then
+               echo "please set CROSS_SYS_ROOT in the environment"
+               return 1
+       fi
+       if [ ! -d "$CROSS_SYS_ROOT" ]; then
+               echo "no sys-root found at $CROSS_SYS_ROOT"
+               return 1
+       fi
+}
+
+fail() {
+       echo
+       echo " *** `basename "$0"` FAILED${*+: $*}"
+       exit 1
+}